home *** CD-ROM | disk | FTP | other *** search
- Path: hecate.umd.edu!ram
- From: ram@mbisgi.umd.edu (Ram Samudrala)
- Newsgroups: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
- Subject: Perl vs. C (was Re: Unix or NT? Get a Mac!)
- Followup-To: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
- Date: 4 Jan 1996 12:04:57 GMT
- Organization: The Centre for Advanced Research in Biotechnology
- Message-ID: <4cgfp9$pje@hecate.umd.edu>
- Reply-To: me@ram.org
- NNTP-Posting-Host: iris3.carb.nist.gov
- X-Newsreader: TIN [version 1.2 PL0]
-
- Cross-posted to comp.lang.c; previous thread in its entirety is in
- comp.infosystems.www.misc.
-
- Mike Heins (mheins@bluestem.prairienet.org) wrote:
-
- >If you are an ACM contest programmer, that is fine. For the rest of
- >us, time spent programming is roughly proportional to lines of code.
-
- Is it really? My iterative solution took me a shorter time to program
- (than the recursive one) even though it has the same # of lines (it
- runs faser too) and as I said the Perl version is about the same
- length. In fact, what I did was write one loop, copy it 9 times, and
- simply went in and changed the variables. With the recursive version
- also I was able to copy lines in at least 2-3 cases.
-
- >And if I remove the same from Tom's, it comes to 20 lines.
-
- All right, I rewrote the program slightly (I don't program like this,
- but I know many people who do) so not be symmetrical, to not use
- multiple lines for declarations (I had 4 lines with "int ..", whereas
- I could just had one line "int x, y, z"), not use multiple lines for
- initialisation (C hack: foo = bar = baz = 2, whic I hate). I get 29
- lines. If used array initalisation when declaring, it'd be about 2
- lines shorter. I did the same for Tom (put the '{'s on a separate
- line), then I issue the command:
-
- sort program | uniq | grep -v '{' | grep -v '}' | wc
-
- For Tom, I get 18 lines, and for my program I get 29. Now, this about
- 1.5 times more than Tom's (hardly the factor of 10 someone claimed).
- I'm sure Tom could put the whole bloody thing in one line... as could
- I. I think this is well within some standard fluctuation. (And I
- will remind you about the iterative solution again.)
-
- >I wasn't privy to that code when I made my post.
-
- No, but I said it was highly similar---did you not believe me?
-
- >All this is fine if you can type as fast as you think. Most people are
- >not ACM contest programmers.
-
- Well, if you read Paul Phillps' post (and actually everone who
- disagreed with me then), that's how this whole thing started. I'm
- sure there're ACM problems that Perl might do better (but I can't
- think of one---anyone?), but the statement "Perl would make it too
- easy" is not at all true. Most of the problems in my experience that
- can be done really fast are problems like this, which are not too
- dependent on language, and I've used many recursive solutions in my
- time.
-
- >count this problem as text-intensive. It is recursion-intensive.
-
- But there's an iterative solution---in fact, it is with the recursive
- solution that Perl actually manages to make the program shorter.
-
- >We already conceded the time to run -- why do you keep harping on
- >it?
-
- Because, again, if you read the original thread, some of the claims
- were like "the factor of time to code is 10 times more and the
- execution speed is only 2-3 times less". Hardly borne out in this
- example, is it? And I agreed this might be true for simple
- algorithms---but as I clearly stated, after the algorithm acquires a
- certain complexity, this is no longer true. My claims were made under
- highly specific situations.
-
- >Perl does not claim to be all things to all people, and I don't think C
- >can claim it either.
-
- I don't and never have disputed this. C shell scripts at some point
- are better than doing it in C, but this whole discussion arose under a
- specific comment I made, which was about complexity and the ACM
- contests.
-
- --Ram
-
- me@ram.org || http://www.ram.org || http://www.twisted-helices.com/th
- Tell me why I have to be a powerslave?
- I don't want to die I'm a god why can't I live on?
- When the life giver dies all around is laid waste.
- And In my last hour I'm a slave to the power of death. ---Iron Maiden
-